#! /bin/sh -e

echo "setting environment config"
echo "$ARTEMIS_WS_URL"
echo "$ARTEMIS_URL"
echo "$RECEIPT_URL"
echo "$PAY_URL"

cat >> /etc/nginx/conf.d/hly-admin.conf <<EOF
server {
    listen      80;
    server_name   $SERVER_NAME;
    location / {
        try_files \$uri /index.html;
        root /app/www/;
    }

    location /oauth/ {
        proxy_pass $ARTEMIS_URL/oauth/;
    }

    location /api/ {
        proxy_pass $ARTEMIS_URL/api/;
    }
    location /receipt/ {
        proxy_pass $RECEIPT_URL/receipt/;
    }

    location /payment/ {
       proxy_pass $PAY_URL/payment/;
    }

    location /budget-service/ {
        proxy_pass $BUDGET_URL/budget-service/;
    }

    location /brms/ {
        proxy_pass $BRMS_URL/brms/;
    }

    location /push/ {
        proxy_pass $PUSH_URL/push/;
    }

    location /vendor-data-service/ {
        proxy_pass $VND_DATA_URL/vendor-data-service/;
    }

    location /amap/{
       proxy_pass http://restapi.amap.com/;
       proxy_redirect off;
       proxy_set_header Host restapi.amap.com;
       client_max_body_size 10m;
       client_body_buffer_size 128k;
       proxy_connect_timeout 90;
       proxy_read_timeout 90;
       proxy_buffer_size 4k;
       proxy_buffers 6 32k;
       proxy_busy_buffers_size 64k;
       proxy_temp_file_write_size 64k;
       root index.php;
    }

}
EOF

echo "starting web server"

nginx -g 'daemon off;'
